﻿using System;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace Common
{
    /// <summary>
    /// 提供对web类的方便
    /// </summary>
    public static class PageHelper
    {
        /// <summary>
        /// Sets the repeater attributes.(设置repeater中某个控件的属性)
        /// </summary>
        /// <param name="repeaterObject">The repeater object.</param>
        /// <param name="controlID">The control ID.</param>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        public static void SetRepeaterAttributes(IEnumerable repeaterObject, string controlID, string key, string value)
        {

            foreach (Control item in repeaterObject)
            {
                WebControl web = (WebControl)item.FindControl(controlID);
                if (web != null)
                {
                    web.Attributes.Add(key, value);
                }
            }
        }
        /// <summary>
        /// HTMLs the encode.
        /// </summary>
        /// <param name="str">The STR.</param>
        /// <returns></returns>
        public static string HtmlEncode(string str)
        {
            return HttpUtility.HtmlEncode(str);
        }
        /// <summary>
        /// HTMLs the decode.
        /// </summary>
        /// <param name="str">The STR.</param>
        /// <returns></returns>
        public static string HtmlDecode(string str)
        {
            return HttpUtility.HtmlDecode(str);
        }
        /// <summary>
        /// HTMLs the encode.
        /// </summary>
        /// <param name="str">The STR.</param>
        /// <returns></returns>
        public static string HtmlEncode(object str)
        {
            if (str==null)
            {
                return null;
            }
            return HttpUtility.HtmlEncode(str.ToString());
        }
        /// <summary>
        /// HTMLs the decode.
        /// </summary>
        /// <param name="str">The STR.</param>
        /// <returns></returns>
        public static string HtmlDecode(object str)
        {
            if (str==null)
            {
                return null;
            }
            return HttpUtility.HtmlDecode(str.ToString());
        }
    }
}
